package com.example.danangtravel.TaxiATM;

import java.io.IOException;
import java.util.ArrayList;
import com.exam.danangtranel.adapter.TbTaxiAdapter;
import com.exam.danangtranel.filed.Taxi;
import com.example.danangtravel.DataAccess;
import com.example.danangtravel.R;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;

public class TaxiActivity extends Activity {
	private ArrayList<Taxi> dataArr;
	private TbTaxiAdapter adapter;
	private ListView lvTaxi;
	private ImageButton btn_hTaxi;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_taxi);

		lvTaxi = (ListView) findViewById(R.id.lvTaxi);
		try {
			DataAccess db = new DataAccess(this);
			dataArr = new ArrayList<Taxi>();
			dataArr = db.getAlTaxi();
			db.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		adapter = new TbTaxiAdapter(this, dataArr);
		lvTaxi.setAdapter(adapter);
		lvTaxi.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
						+ dataArr.get(arg2).getPhone().trim())));
			}
		});

		btn_hTaxi = (ImageButton) findViewById(R.id.btn_hTaxi);
		btn_hTaxi.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				finish();
			}
		});
	}
}
